<?php

namespace app\home\controller;


use app\common\model\MessageModel;
use helper\Qrcode as QrcodeAlias;
use think\facade\Config;
use think\facade\Db;
use think\View;

class IndexController extends BaseController
{


  public function __construct()
  {
    parent::__construct();

  }

  public function index()
  {
    $newList = Db::name('cms_detail_article')->where('is_recommend',1)->limit(6)->select();
    $this->assign('new_list',$newList);
    return $this->fetch();
  }

  public function page()
  {
    $tpl = $this->request->param('tpl');
    return $this->fetch($tpl);
  }

  public function qrcode(){
    $text = $this->request->param('text');
    return QrcodeAlias::img(html_out($text));
  }


  /*在线预约*/
  public function message(){
    if ($this->request->isAjax()){
      try {
        $data = $this->request->param();
        $vdata = [
            'name|您的称呼' =>'require',
            'mobile|你的手机号' =>'require',
            'email|邮箱' =>'require',
            'content|留言内容'=>'require',
        ];
        $result = $this->validate($data,$vdata);
        if (true !== $result) {
          exception($result, 40001);
        }
        $messageModel = new MessageModel();
        $messageModel->add($data);
      } catch (\Exception $e) {
        $this->error($e->getMessage());
      }
      $this->success('提交成功');
    }
    return $this->fetch();
  }
}
